package com.ksm.zyz.controller;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ksm.zyz.common.base.BaseController;
import com.ksm.zyz.sys.entity.BaseMemberInfo;
import com.ksm.zyz.sys.entity.BaseMemberLog;
import com.ksm.zyz.sys.entity.BsData;
import com.ksm.zyz.sys.entity.ExtData;
import com.ksm.zyz.sys.serverentity.sBaseMemberInfo;
import com.ksm.zyz.sys.serverentity.sBaseMemberLog;
import com.ksm.zyz.sys.serverservice.sBaseMemberInfoService;
import com.ksm.zyz.sys.serverservice.sBaseMemberLogService;
import com.ksm.zyz.sys.service.baseMemberInfoService;
import com.ksm.zyz.sys.service.baseMemberLogService;

/**
 * @author liuhao
 *
 */
@Controller
@RequestMapping("BaseMemberTongBu")
public class BaseMemberController extends BaseController<sBaseMemberInfo> {

	@Autowired
	private sBaseMemberInfoService sService;
	@Autowired
	private baseMemberInfoService Service;
	@Autowired
	private sBaseMemberLogService sMemberService;
	@Autowired
	private baseMemberLogService MemberService;


	   @RequestMapping(value ="BaseMemberInfo")
	    @ResponseBody
		public ExtData BaseSupplierInfo(int ming, HttpServletRequest req){
	         //List<sOrderMemberInfo> list=sMemberService.selectSome();
		   int scount=(int)sService.selectAllCount();
		   int count=(int)Service.selectCount(ming);
		   int begin=0;
		   if(scount>count)
		   {			   
			   begin=count;
		   }
		   else{
			   extData.setTotalCount(0);
			   return extData;
		   }
		   System.out.println(scount+"总数据量");
			   sBaseMemberInfo sInfo =new sBaseMemberInfo();
			   BsData bsdata=new BsData();
			   bsdata.setBegin(begin);
			   bsdata.setLimit(scount);
			   sInfo.setBsData(bsdata);
			   List<BaseMemberInfo> list=sService.selectAllInfo(sInfo);
			   for(int j=0;j<list.size();j++)
			   {
				   BaseMemberInfo info=list.get(j);
				   System.out.println(list.get(j).getMemberName());
				   info.setSmId(ming);			   				   
				  try
				   {
					   Service.insertSelective(info);					   
				   }
				   catch(Exception e){
					   System.out.println(info.getMid()+"@@@@@");
					   extData.setTotalCount(j);
					   return extData;   
				   }
				   
			   }
			     			   
		   extData.setTotalCount(scount-count);	
	               
			return extData;    
		}
	   @RequestMapping(value ="BaseMemberLog")
	    @ResponseBody
		public ExtData BaseSupplierMember(int ming, HttpServletRequest req){
	         //List<sOrderMemberInfo> list=sMemberService.selectSome();
		   int scount=(int)sMemberService.selectAllCount();
		   int count=(int)MemberService.selectCount(ming);
		   int begin=0;
		   if(scount>count)
		   {			   
			   begin=count;
		   }
		   else{
			   extData.setTotalCount(0);
			   return extData;
		   }
		   System.out.println(scount+"总数据量");
			   sBaseMemberLog sInfo =new sBaseMemberLog();
			   BsData bsdata=new BsData();
			   bsdata.setBegin(begin);
			   bsdata.setLimit(scount);
			   sInfo.setBsData(bsdata);
			   List<BaseMemberLog> list=sMemberService.selectAllInfo(sInfo);
			   for(int j=0;j<list.size();j++)
			   {
				   BaseMemberLog info=list.get(j);
				   System.out.println(list.get(j).getMemberName());
				   info.setSmId(ming);			   				   
				  try
				   {
					  MemberService.insertSelective(info);					   
				   }
				   catch(Exception e){
					   System.out.println(info.getId()+"@@@@@");
					   extData.setTotalCount(j);
					   return extData;   
				   }
				   
			   }
			     			   
		   extData.setTotalCount(scount-count);	
	               
			return extData;    
		}
	   

}
